<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Models\Goods;
use App\Models\GoodsCategory;
use Faker\Generator as Faker;

$factory->define(Goods::class, function (Faker $faker) {

    $name = $faker->title;

    // 随机取一个月以内的时间
    $updated_at = $faker->dateTimeThisMonth();
    $goods_category_ids = GoodsCategory::where("level",2)->get()->pluck("id");
    // 为创建时间传参，意为最大不超过 $updated_at，因为创建时间需永远比更改时间要早
    $created_at = $faker->dateTimeThisMonth($updated_at);
// 头像假数据
    $avatars = [
        'https://cdn.learnku.com/uploads/images/201710/14/1/s5ehp11z6s.png',
        'https://cdn.learnku.com/uploads/images/201710/14/1/Lhd1SHqu86.png',
        'https://cdn.learnku.com/uploads/images/201710/14/1/LOnMrqbHJn.png',
        'https://cdn.learnku.com/uploads/images/201710/14/1/xAuDMxteQy.png',
        'https://cdn.learnku.com/uploads/images/201710/14/1/ZqM7iaP4CR.png',
        'https://cdn.learnku.com/uploads/images/201710/14/1/NDnzMutoxX.png',
    ];
    return [
        'name' => $name,
        'goods_category_id' => $faker->randomElement($goods_category_ids),
        'created_at' => $created_at,
        'updated_at' => $updated_at,
        "img"=>$faker->randomElement($avatars),
        "price"=>99,
        "on_sale"=>1,
        "discounts"=>0,
    ];
});
